import 'IStateMachine.dart';
import 'ITransition.dart';

abstract class IState
{
  String? get name;
  String? get tag => null;

  Map<String, ITransition>? transitions = {};

  void onEnter(IState? prev);
  void onExit(IState? next);
  void onUpdate(ITransition transition) {
    transition.fromState = this;
    if(transition.check()) {
      _parent.setCurTransition(transition);
      _parent.setCurState(transition.toState);
    }
  }
  
  void addTransition(ITransition? transition) {
    if(transition == null || transition.name == null || transition.name == "") return;
    transitions![transition.name!] = transition;
  }
  
  late IStateMachine _parent;
  void setStateMachine(IStateMachine stateMachine) {
    _parent = stateMachine;
  }
}
